package com.cnswhy.cloud.server.merchant.controller.spell;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cnswhy.cloud.common.core.exception.BizException;
import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.common.core.utils.CnswhyUtil;
import com.cnswhy.cloud.common.core.utils.SystemClockUtil;
import com.cnswhy.cloud.common.logging.uitls.MDCUtil;
import com.cnswhy.cloud.common.rabbitmq.service.MessageService;
import com.cnswhy.cloud.common.redis.service.IdGeneratorService;
import com.cnswhy.cloud.common.redis.service.RedisService;
import com.cnswhy.cloud.server.common.entity.constant.AmqpExchange;
import com.cnswhy.cloud.server.common.entity.enumeration.TransType;
import com.cnswhy.cloud.server.common.entity.enumeration.WalletType;
import com.cnswhy.cloud.server.common.entity.mq.SpellDayendCancelMsg;
import com.cnswhy.cloud.server.common.entity.mq.SpellInfoMsg;
import com.cnswhy.cloud.server.core.constant.RedisConstant;
import com.cnswhy.cloud.server.core.entity.*;
import com.cnswhy.cloud.server.core.dto.SpellReportSaveDTO;
import com.cnswhy.cloud.server.core.dto.SpellReportUpdateDTO;
import com.cnswhy.cloud.server.core.dto.SpellReportPageDTO;
import com.cnswhy.cloud.server.core.oem.OemService;
import com.cnswhy.cloud.server.core.query.QueryGenerator;
import com.cnswhy.cloud.server.core.service.IntegralLogService;
import com.cnswhy.cloud.server.core.service.SpellInfoService;
import com.cnswhy.cloud.server.core.service.SpellReportService;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.cnswhy.cloud.common.core.base.controller.SuperController;
import com.cnswhy.cloud.common.core.base.R;
import com.cnswhy.cloud.server.core.service.WalletTransDtlService;
import com.cnswhy.cloud.server.core.service.customer.CustomerPrivilegeService;
import com.cnswhy.cloud.server.core.service.customer.CustomerService;
import com.cnswhy.cloud.server.core.service.shop.ShopProductService;
import com.cnswhy.cloud.server.core.service.spell.SpellOrderService;
import com.cnswhy.cloud.server.core.service.spell.SpellPriceService;
import com.cnswhy.cloud.server.core.wallet.WalletService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
//import com.github.zuihou.security.annotation.PreAuth;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-16
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/spellReport")
@Api(value = "SpellReport", tags = "")
//@PreAuth(replace = "spellReport:")
public class SpellReportController extends SuperController<SpellReportService, Long, SpellReport, SpellReportPageDTO, SpellReportSaveDTO, SpellReportUpdateDTO> {
    @Autowired
    MessageService messageService;
    @PostMapping("/rebuildReport")
    public R<Boolean> rebuildReport(String settDate) {
        SpellDayendCancelMsg spellDayendCancelMsg = SpellDayendCancelMsg.builder().settDate(settDate).build();
        spellDayendCancelMsg.setTraceId(MDCUtil.getTraceId());
        messageService.sendQueueByObject(AmqpExchange.REPORT_MESSAGE,spellDayendCancelMsg);

        return R.success(null);
    }
    /*@PostMapping("/reportRecycle")
    public R<Boolean> reportRecycle(String settDate) {
        SpellDayendCancelMsg spellDayendCancelMsg = SpellDayendCancelMsg.builder().settDate(settDate).build();
        spellDayendCancelMsg.setTraceId(MDCUtil.getTraceId());
        return R.success(null);
    }*/
    @Autowired
    WalletTransDtlService walletTransDtlService;

    @Autowired
    SpellPriceService spellPriceService;
    @Autowired
    IdGeneratorService idGeneratorService;
    @Autowired
    SpellOrderService spellOrderService;
    @Autowired
    CustomerService customerService;
    @Autowired
    CustomerPrivilegeService customerPrivilegeService;
    @Autowired
    WalletService walletService;
    @Autowired
    RedisService redisService;
    @Autowired
    ShopProductService shopProductService;
    @Autowired
    IntegralLogService integralLogService;
    @Autowired
    SpellInfoService spellInfoService;
    @Autowired
    OemService oemService;
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<SpellReport> spellReportList = list.stream().map((map) -> {
            SpellReport spellReport = SpellReport.builder().build();
            return spellReport;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(spellReportList));
    }
}
